<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2019/4/23
 * Time: 下午3:37
 */

namespace App\Http\Controllers;


use App\Http\Model\OutJson;
use App\Http\Services\RoomHotServices;
use App\Http\Services\SystemConfigServices;
use Illuminate\Http\Request;
use App\Http\Model\Hint;
use App\Lib\Response;

class RoomHotController extends BaseController
{
    private $service_room_hot;
    public function __construct()
    {
        $this->service_room_hot = new RoomHotServices();
    }

    /**@params int 0获取热门，大于0获取类型房间
     * @return array(code msg data) 热门的房间列表 
     * @desc 获取热门或根据类型获取房间列表v3
     * @author zxiaofee
     * @date 2021.12.27
     */
    public function get_hot_v3(Request $request){
        //增加房间列表开关
        $hotRoomListShowConfig = (new SystemConfigServices())->getHotRoomListShowConfig();
        if (!$hotRoomListShowConfig){
            Response::returnResult(Hint::SUCCESS);
        }

        $userId = $this->getLoginUserId();
        if(empty($userId)) {
            Response::returnResult(Hint::LOGIN_OUT);
        }

        $page = $request->get("page")??0;
        $type = $request->get("type")??-1;
        $data = $this->service_room_hot->hot_v3($userId, $page, $type);

        Response::returnResult(Hint::SUCCESS, ['list'=>$data]);
    }



    /**@params null
     * @return array(code, msg)code=0执行成功，code><0失败
     * @desc 更新es房间数据接口，crontab配置每n秒执行一次
     * @author zxiaofee
     * @date 2021.12.27
     */
    public function update_es_room_data_task(){
        $result = $this->service_room_hot->update_es_room_data();
        $data = array('result' => $result);
        OutJson::outJsonResult(Hint::SUCCESS, $data);
    }

    public function getNoneByType(Request $request){
        $data = $this->service_room_hot->none_top(100);

        Response::returnResult(Hint::SUCCESS, $data);
    }

}